package net.zoneland.knowledge.dao;

import net.zoneland.knowledge.model.*;
import net.zoneland.knowledge.service.bean.WorkReminderVo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface WorkReminderMapper {

    /**
     * 省公司提醒列表查询信息
     * @param vo 查询条件
     * @return 省公司主表列表
     */
    @Select({
            "<script>",
            "SELECT A.ID, A.WORK_ORDER_ID, A.MATTER_DESCRIPTION, A.USER_ID, ",
            "A.SAN_KE_KEYWORDS, A.WORK_TYPE, A.CREATE_TIME, A.UPDATE_TIME, A.DEL, A.WORK_STATUS, A.SENDER_IDS, ",
            "A.USER_NAME, A.TASK_STATUS, A.ISSUED_TIME, A.FINISH_TIME ",
            "FROM AITK_PROVINCE_MAIN_WORK A ",
            "left join AITK_PROVINCE_SUB_WORK B on A.WORK_ORDER_ID = B.MAIN_WORK_ID  where 1=1 ",
            "<if test=\"workStatus != null and workStatus != ''\"> AND A.WORK_STATUS=#{workStatus,jdbcType=VARCHAR} </if> ",
            "<if test=\"startTime != null \"> AND A.UPDATE_TIME &gt;= #{startTime}</if> ",
            "<if test=\"endTime != null \"> AND A.UPDATE_TIME &lt;= #{endTime} </if> ",
            "GROUP BY A.ID, A.WORK_ORDER_ID, A.MATTER_DESCRIPTION, A.USER_ID, A.SAN_KE_KEYWORDS, A.WORK_TYPE, ",
            "A.CREATE_TIME, A.UPDATE_TIME, A.DEL, A.WORK_STATUS, A.SENDER_IDS, A.USER_NAME, A.TASK_STATUS, A.ISSUED_TIME, A.FINISH_TIME",
            "ORDER BY DECODE(A.WORK_STATUS, '未下发', A.WORK_STATUS), A.UPDATE_TIME DESC",
            "</script>"
    })
    @Results(id = "ProvinceMainWorkMap",value = {
            @Result(column = "ID", property = "id", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "WORK_ORDER_ID", property = "workOrderId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "MATTER_DESCRIPTION", property = "matterDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "USER_ID", property = "userId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "SAN_KE_KEYWORDS", property = "sanKeKeywords", jdbcType = JdbcType.VARCHAR),
            @Result(column = "WORK_TYPE", property = "workType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "CREATE_TIME", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "UPDATE_TIME", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "DEL", property = "del", jdbcType = JdbcType.INTEGER),
            @Result(column = "WORK_STATUS", property = "workStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "SENDER_IDS", property = "senderIds", jdbcType = JdbcType.VARCHAR),
            @Result(column = "USER_NAME", property = "userName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "TASK_STATUS", property = "taskStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ISSUED_TIME", property = "issuedTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "FINISH_TIME", property = "finishTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "SUB_WORK_DESCRIPTIONS", property = "subWorkDescriptions", jdbcType = JdbcType.VARCHAR),
            @Result(column = "DETAILED_DESCRIPTIONS", property = "detailedDescriptions", jdbcType = JdbcType.VARCHAR),
    })
    List<TaskReminderMainWork> getProvinceMainWorkList(final WorkReminderVo vo);

    /**
     * 根据主工单id查询主工单信息
     * @param mainWorkId 主工单编号
     * @return 主工单信息
     */
    @Select({
            "<script>",
            "SELECT ID, WORK_ORDER_ID, MATTER_DESCRIPTION, USER_ID, ",
            "SAN_KE_KEYWORDS, WORK_TYPE, CREATE_TIME, UPDATE_TIME, DEL, WORK_STATUS, SENDER_IDS, ",
            "USER_NAME, TASK_STATUS, ISSUED_TIME, FINISH_TIME ",
            "FROM AITK_PROVINCE_MAIN_WORK",
            "where WORK_ORDER_ID = #{mainWorkId,jdbcType=VARCHAR}",
            "ORDER BY CREATE_TIME DESC",
            "</script>"
    })
    @ResultMap(value = {"ProvinceMainWorkMap"})
    TaskReminderMainWork getProvinceMainWorkByMainWorkId(@Param("mainWorkId") final String mainWorkId);

    /**
     * 省公司子表列表查询信息
     * @param mainWork 查询条件
     * @return 省公司子表列表
     */
    @Select({
            "<script>",
            "SELECT ID, SUB_WORK_ID, IMPLEMENTED_INITIATIVES, DETAILED_DESCRIPTION, PLAN_TIME, ",
            "COMPLETION_MARK, CREATE_TIME, DEL, MAIN_WORK_ID, SUB_WORK_DESCRIPTION, REMARKS, UPDATE_TIME ",
            "FROM AITK_PROVINCE_SUB_WORK ",
            "where MAIN_WORK_ID = #{workOrderId,jdbcType=VARCHAR}",
            "ORDER BY CREATE_TIME ASC",
            "</script>"
    })
    @Results(id = "SubWorkMap", value = {
            @Result(column = "ID", property = "id", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "SUB_WORK_ID", property = "subWorkId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "IMPLEMENTED_INITIATIVES", property = "implementedInitiatives", jdbcType = JdbcType.VARCHAR),
            @Result(column = "DETAILED_DESCRIPTION", property = "detailedDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PLAN_TIME", property = "planTime", jdbcType = JdbcType.VARCHAR),
            @Result(column = "COMPLETION_MARK", property = "completionMark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "CREATE_TIME", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "DEL", property = "del", jdbcType = JdbcType.INTEGER),
            @Result(column = "MAIN_WORK_ID", property = "mainWorkId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "SUB_WORK_DESCRIPTION", property = "subWorkDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "REMARKS", property = "remarks", jdbcType = JdbcType.VARCHAR),
            @Result(column = "UPDATE_TIME", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
    })
    List<TaskReminderSubWork> getProvinceSubWorkList(final TaskReminderMainWork mainWork);

    /**
     * 获取省公司导出列表的信息
     * @param vo 查询条件
     * @return 省公司导出列表的信息
     */
    @Select({
            "<script>",
            "SELECT A.MATTER_DESCRIPTION, A.SAN_KE_KEYWORDS, A.WORK_TYPE, A.UPDATE_TIME, A.WORK_STATUS, ",
            "A.USER_NAME, A.ISSUED_TIME, A.FINISH_TIME, A.UPDATE_TIME, B.IMPLEMENTED_INITIATIVES, B.DETAILED_DESCRIPTION, B.PLAN_TIME, ",
            "B.COMPLETION_MARK, B.SUB_WORK_DESCRIPTION, B.REMARKS ",
            "FROM AITK_PROVINCE_MAIN_WORK A ",
            "left join AITK_PROVINCE_SUB_WORK B on A.WORK_ORDER_ID = B.MAIN_WORK_ID  where 1=1 ",
            "<if test=\"workStatus != null and workStatus != ''\"> AND A.WORK_STATUS=#{workStatus,jdbcType=VARCHAR} </if> ",
            "<if test=\"startTime != null \"> AND A.UPDATE_TIME &gt;= #{startTime}</if> ",
            "<if test=\"endTime != null \"> AND A.UPDATE_TIME &lt;= #{endTime} </if> ",
            "ORDER BY DECODE(A.WORK_STATUS, '未下发', A.WORK_STATUS), A.UPDATE_TIME DESC",
            "</script>"
    })
    @Results({
            @Result(column = "MATTER_DESCRIPTION", property = "matterDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "SAN_KE_KEYWORDS", property = "sanKeKeywords", jdbcType = JdbcType.VARCHAR),
            @Result(column = "WORK_TYPE", property = "workType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "WORK_STATUS", property = "workStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "USER_NAME", property = "userName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ISSUED_TIME", property = "issuedTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "FINISH_TIME", property = "finishTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "IMPLEMENTED_INITIATIVES", property = "implementedInitiatives", jdbcType = JdbcType.VARCHAR),
            @Result(column = "DETAILED_DESCRIPTION", property = "detailedDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PLAN_TIME", property = "planTime", jdbcType = JdbcType.VARCHAR),
            @Result(column = "COMPLETION_MARK", property = "completionMark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "SUB_WORK_DESCRIPTION", property = "subWorkDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "REMARKS", property = "remarks", jdbcType = JdbcType.VARCHAR),
    })
    List<ProvinceReminderMainWorkExcelVo> getProvinceMainWorkExportList(final WorkReminderVo vo);

    /**
     * 获取市公司导出列表的信息
     * @param vo 查询条件
     * @return 市公司导出列表信息
     */
    @Select({
            "<script>",
            "SELECT A.WORK_ORDER_ID, A.MATTER_DESCRIPTION, A.SAN_KE_KEYWORDS, A.WORK_TYPE, A.UPDATE_TIME, A.WORK_STATUS, ",
            "A.USER_NAME, A.ISSUED_TIME, A.FINISH_TIME, A.COMPANY_NAME, A.UPDATE_TIME, B.IMPLEMENTED_INITIATIVES, B.DETAILED_DESCRIPTION, B.PLAN_TIME, ",
            "B.COMPLETION_MARK, B.SUB_WORK_DESCRIPTION, B.REMARKS ",
            "FROM AITK_CITY_MAIN_WORK A ",
            "left join AITK_CITY_SUB_WORK B on A.WORK_ORDER_ID = B.MAIN_WORK_ID  where A.READ_TYPE != 'refuse' ",
            "<if test=\"workStatus != null and workStatus != ''\"> AND A.WORK_STATUS=#{workStatus,jdbcType=VARCHAR} </if> ",
            "<if test=\"readType != null and readType != ''\"> AND A.READ_TYPE=#{readType,jdbcType=VARCHAR} </if> ",
            "<if test=\"companyName != null and companyName != ''\"> AND A.COMPANY_NAME=#{companyName,jdbcType=VARCHAR} </if> ",
            "<if test=\"startTime != null \"> AND A.UPDATE_TIME &gt;= #{startTime}</if> ",
            "<if test=\"endTime != null \"> AND A.UPDATE_TIME &lt;= #{endTime} </if> ",
            "ORDER BY DECODE(A.WORK_STATUS, '未分派', 1, '已分派', 2, '已下发', 3, A.WORK_STATUS), A.UPDATE_TIME DESC",
            "</script>"
    })
    @Results({
            @Result(column = "WORK_ORDER_ID", property = "workOrderId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "MATTER_DESCRIPTION", property = "matterDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "SAN_KE_KEYWORDS", property = "sanKeKeywords", jdbcType = JdbcType.VARCHAR),
            @Result(column = "WORK_TYPE", property = "workType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "WORK_STATUS", property = "workStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "USER_NAME", property = "userName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "COMPANY_NAME", property = "companyName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ISSUED_TIME", property = "issuedTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "FINISH_TIME", property = "finishTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "IMPLEMENTED_INITIATIVES", property = "implementedInitiatives", jdbcType = JdbcType.VARCHAR),
            @Result(column = "DETAILED_DESCRIPTION", property = "detailedDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PLAN_TIME", property = "planTime", jdbcType = JdbcType.VARCHAR),
            @Result(column = "COMPLETION_MARK", property = "completionMark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "SUB_WORK_DESCRIPTION", property = "subWorkDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "REMARKS", property = "remarks", jdbcType = JdbcType.VARCHAR),
    })
    List<CityReminderMainWorkExcelVo> getCityMainWorkExportList(final WorkReminderVo vo);

    /**
     * 获取支部公司导出列表的信息
     * @param vo 查询条件
     * @return 支部公司导出列表的信息
     */
    @Select({
            "<script>",
            "SELECT A.MATTER_DESCRIPTION, A.SAN_KE_KEYWORDS, A.WORK_TYPE, A.UPDATE_TIME, A.WORK_STATUS, ",
            "A.USER_NAME, A.ISSUED_TIME, A.FINISH_TIME, A.FINISH_STATUS, A.UPDATE_TIME, B.IMPLEMENTED_INITIATIVES, B.DETAILED_DESCRIPTION, B.PLAN_TIME, ",
            "B.COMPLETION_MARK, B.SUB_WORK_DESCRIPTION, B.REMARKS ",
            "FROM AITK_BRANCH_MAIN_WORK A ",
            "left join AITK_BRANCH_SUB_WORK B on A.WORK_ORDER_ID = B.MAIN_WORK_ID  where 1=1 ",
            "<if test=\"workStatus != null and workStatus != ''\"> AND A.WORK_STATUS=#{workStatus,jdbcType=VARCHAR} </if> ",
            "<if test=\"readType != null and readType != ''\"> AND A.READ_TYPE=#{readType,jdbcType=VARCHAR} </if> ",
            "<if test=\"companyName != null and companyName != ''\"> AND A.COMPANY_NAME=#{companyName,jdbcType=VARCHAR} </if> ",
            "<if test=\"orgUuid != null and orgUuid != ''\"> AND A.ORG_UUID=#{orgUuid,jdbcType=VARCHAR} </if> ",
            "<if test=\"startTime != null \"> AND A.UPDATE_TIME &gt;= #{startTime}</if> ",
            "<if test=\"endTime != null \"> AND A.UPDATE_TIME &lt;= #{endTime} </if> ",
            "ORDER BY DECODE(A.FINISH_STATUS, '已完成', A.FINISH_STATUS), A.FINISH_TIME asc",
            "</script>"
    })
    @Results({
            @Result(column = "MATTER_DESCRIPTION", property = "matterDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "SAN_KE_KEYWORDS", property = "sanKeKeywords", jdbcType = JdbcType.VARCHAR),
            @Result(column = "WORK_TYPE", property = "workType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "WORK_STATUS", property = "workStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "USER_NAME", property = "userName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ISSUED_TIME", property = "issuedTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "FINISH_TIME", property = "finishTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "FINISH_STATUS", property = "finishStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "IMPLEMENTED_INITIATIVES", property = "implementedInitiatives", jdbcType = JdbcType.VARCHAR),
            @Result(column = "DETAILED_DESCRIPTION", property = "detailedDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PLAN_TIME", property = "planTime", jdbcType = JdbcType.VARCHAR),
            @Result(column = "COMPLETION_MARK", property = "completionMark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "SUB_WORK_DESCRIPTION", property = "subWorkDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "REMARKS", property = "remarks", jdbcType = JdbcType.VARCHAR),
    })
    List<BranchReminderMainWorkExcelVo> getBranchMainWorkExportList(final WorkReminderVo vo);

    /**
     * 新增省公司主表信息
     * @param mainWork 新增内容
     */
    @Insert({
            "insert into AITK_PROVINCE_MAIN_WORK (ID, WORK_ORDER_ID, MATTER_DESCRIPTION, USER_ID, ",
            "SAN_KE_KEYWORDS, WORK_TYPE, CREATE_TIME, UPDATE_TIME, DEL, WORK_STATUS, SENDER_IDS, USER_NAME, ",
            "TASK_STATUS, ISSUED_TIME, FINISH_TIME )",
            "values ",
            "(#{id,jdbcType=VARCHAR}, #{workOrderId,jdbcType=VARCHAR}, #{matterDescription,jdbcType=VARCHAR}, ",
            "#{userId,jdbcType=VARCHAR}, #{sanKeKeywords,jdbcType=VARCHAR}, ",
            "#{workType,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ",
            " #{del,jdbcType=INTEGER}, #{workStatus,jdbcType=VARCHAR}, ",
            "#{senderIds,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, #{taskStatus,jdbcType=VARCHAR}, ",
            "#{issuedTime,jdbcType=TIMESTAMP}, #{finishTime,jdbcType=TIMESTAMP} )"
    })
    void insertProvinceMainWork(final TaskReminderMainWork mainWork);

    /**
     * 新增省公司子表信息
     * @param subWork 新增内容列表
     */
    @Insert({
            "insert into AITK_PROVINCE_SUB_WORK(ID, SUB_WORK_ID, IMPLEMENTED_INITIATIVES, ",
            "DETAILED_DESCRIPTION, PLAN_TIME, COMPLETION_MARK, CREATE_TIME, DEL, MAIN_WORK_ID, SUB_WORK_DESCRIPTION, ",
            "REMARKS, UPDATE_TIME )",
            "values ",
            "(#{id, jdbcType=VARCHAR}, #{subWorkId, jdbcType=VARCHAR}, #{implementedInitiatives, jdbcType=VARCHAR}, ",
            "#{detailedDescription, jdbcType=VARCHAR}, #{planTime, jdbcType=VARCHAR}, #{completionMark, jdbcType=VARCHAR}, ",
            "#{createTime, jdbcType=TIMESTAMP}, #{del, jdbcType=INTEGER}, #{mainWorkId, jdbcType=INTEGER}, ",
            "#{subWorkDescription, jdbcType=VARCHAR}, #{remarks, jdbcType=VARCHAR}, #{updateTime, jdbcType=TIMESTAMP} )",
    })
    void insertProvinceSubWork(final TaskReminderSubWork subWork);

    /**
     * 修改省公司主表信息
     * @param mainWork 主表信息
     */
    @Update({
            "update AITK_PROVINCE_MAIN_WORK set MATTER_DESCRIPTION = #{matterDescription,jdbcType=VARCHAR}, ",
            "USER_ID = #{userId,jdbcType=VARCHAR}, ",
            "SAN_KE_KEYWORDS = #{sanKeKeywords,jdbcType=VARCHAR}, WORK_TYPE = #{workType,jdbcType=VARCHAR}, ",
            "CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}, UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP}, ",
            "DEL = #{del,jdbcType=INTEGER}, ",
            "WORK_STATUS = #{workStatus,jdbcType=VARCHAR}, SENDER_IDS = #{senderIds,jdbcType=VARCHAR}, ",
            "USER_NAME = #{userName,jdbcType=VARCHAR}, TASK_STATUS = #{taskStatus,jdbcType=VARCHAR}, ",
            "ISSUED_TIME = #{issuedTime,jdbcType=TIMESTAMP}, FINISH_TIME = #{finishTime,jdbcType=TIMESTAMP} ",
            "where WORK_ORDER_ID = #{workOrderId,jdbcType=VARCHAR}"
    })
    void updateProvinceMainWork(final TaskReminderMainWork mainWork);

    /**
     * 修改省公司子表信息
     * @param subWork 子表信息
     */
    @Update({
            "update AITK_PROVINCE_SUB_WORK set IMPLEMENTED_INITIATIVES = #{implementedInitiatives,jdbcType=VARCHAR}, ",
            "DETAILED_DESCRIPTION = #{detailedDescription, jdbcType=VARCHAR}, PLAN_TIME = #{planTime, jdbcType=VARCHAR}, ",
            "COMPLETION_MARK = #{completionMark, jdbcType=VARCHAR}, CREATE_TIME = #{createTime, jdbcType=TIMESTAMP}, ",
            "DEL = #{del, jdbcType=INTEGER}, MAIN_WORK_ID = #{mainWorkId, jdbcType=VARCHAR}, ",
            "SUB_WORK_DESCRIPTION = #{subWorkDescription, jdbcType=VARCHAR}, REMARKS = #{remarks, jdbcType=VARCHAR}, ",
            "UPDATE_TIME = #{updateTime, jdbcType=TIMESTAMP} ",
            "where SUB_WORK_ID = #{subWorkId,jdbcType=VARCHAR}"
    })
    void updateProvinceSubWork(final TaskReminderSubWork subWork);

    /**
     * 删除省公司主表信息
     * @param mainWork 主表信息
     */
    @Delete({
            "delete from AITK_PROVINCE_MAIN_WORK where WORK_ORDER_ID = #{workOrderId,jdbcType=VARCHAR}"
    })
    void deleteProvinceMainWork(final TaskReminderMainWork mainWork);

    /**
     * 删除省公司子表信息
     * @param subWorkIds 子表id
     */
    @Delete({
            "<script>",
            "delete from AITK_PROVINCE_SUB_WORK where SUB_WORK_ID in ",
            "<foreach collection='subWorkIds' index='index' item='item' open='(' separator=',' close=')'>",
            "#{item}</foreach> ",
            "</script>"
    })
    void deleteProvinceSubWork(@Param("subWorkIds") final List<String> subWorkIds);

    /**
     * 新增市公司主表信息
     * @param mainWork 新增内容
     */
    @Insert({
            "insert into AITK_CITY_MAIN_WORK (ID, WORK_ORDER_ID, MATTER_DESCRIPTION, USER_ID, ",
            "SAN_KE_KEYWORDS, WORK_TYPE, CREATE_TIME, UPDATE_TIME, DEL, WORK_STATUS, SENDER_IDS, ",
            "COMPANY_NAME, HANDLER_ID, USER_NAME, HANDLER_NAME, READ_TYPE, PARENT_WORK_ID, TASK_STATUS, ISSUED_TIME, FINISH_TIME)",
            "values ",
            "(#{id,jdbcType=VARCHAR}, #{workOrderId,jdbcType=VARCHAR}, #{matterDescription,jdbcType=VARCHAR}, ",
            "#{userId,jdbcType=VARCHAR}, #{sanKeKeywords,jdbcType=VARCHAR}, ",
            "#{workType,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ",
            "#{del,jdbcType=INTEGER}, #{workStatus,jdbcType=VARCHAR}, ",
            "#{senderIds,jdbcType=VARCHAR}, #{companyName,jdbcType=VARCHAR}, #{handlerId,jdbcType=VARCHAR}, ",
            "#{userName,jdbcType=VARCHAR}, #{handlerName,jdbcType=VARCHAR}, #{readType,jdbcType=VARCHAR}, ",
            "#{parentWorkId,jdbcType=VARCHAR}, #{taskStatus,jdbcType=VARCHAR}, #{issuedTime,jdbcType=TIMESTAMP}, #{finishTime,jdbcType=TIMESTAMP} )",
    })
    void insertCityMainWork(final TaskReminderMainWork mainWork);

    /**
     * 新增市公司子表信息
     * @param subWork 新增内容列表
     */
    @Insert({
            "insert into AITK_CITY_SUB_WORK(ID, SUB_WORK_ID, IMPLEMENTED_INITIATIVES, ",
            "DETAILED_DESCRIPTION, PLAN_TIME, COMPLETION_MARK, CREATE_TIME, DEL, MAIN_WORK_ID, SUB_WORK_DESCRIPTION, ",
            "REMARKS, UPDATE_TIME )",
            "values ",
            "(#{id, jdbcType=VARCHAR}, #{subWorkId, jdbcType=VARCHAR}, #{implementedInitiatives, jdbcType=VARCHAR}, ",
            "#{detailedDescription, jdbcType=VARCHAR}, #{planTime, jdbcType=VARCHAR}, #{completionMark, jdbcType=VARCHAR}, ",
            "#{createTime, jdbcType=TIMESTAMP}, #{del, jdbcType=INTEGER}, #{mainWorkId, jdbcType=VARCHAR}, ",
            "#{subWorkDescription, jdbcType=VARCHAR}, #{remarks, jdbcType=VARCHAR}, #{updateTime, jdbcType=TIMESTAMP} )",
    })
    void insertCitySubWork(final TaskReminderSubWork subWork);

    /**
     * 修改市公司主表信息
     * @param mainWork 主表信息
     */
    @Update({
            "update AITK_CITY_MAIN_WORK set MATTER_DESCRIPTION = #{matterDescription,jdbcType=VARCHAR}, ",
            "USER_ID = #{userId,jdbcType=VARCHAR}, ",
            "SAN_KE_KEYWORDS = #{sanKeKeywords,jdbcType=VARCHAR}, WORK_TYPE = #{workType,jdbcType=VARCHAR}, ",
            "CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}, UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP}, ",
            "DEL = #{del,jdbcType=INTEGER}, ",
            "WORK_STATUS = #{workStatus,jdbcType=VARCHAR}, SENDER_IDS = #{senderIds,jdbcType=VARCHAR}, ",
            "COMPANY_NAME = #{companyName,jdbcType=VARCHAR}, HANDLER_ID = #{handlerId,jdbcType=VARCHAR}, ",
            "USER_NAME = #{userName,jdbcType=VARCHAR}, HANDLER_NAME = #{handlerName,jdbcType=VARCHAR}, ",
            "READ_TYPE = #{readType,jdbcType=VARCHAR}, TASK_STATUS = #{taskStatus,jdbcType=VARCHAR}, ",
            "ISSUED_TIME = #{issuedTime,jdbcType=TIMESTAMP}, FINISH_TIME = #{finishTime,jdbcType=TIMESTAMP}",
            "where WORK_ORDER_ID = #{workOrderId,jdbcType=VARCHAR}"
    })
    void updateCityMainWork(final TaskReminderMainWork mainWork);

    /**
     * 修改市公司子表信息
     * @param subWork 子表信息
     */
    @Update({
            "update AITK_CITY_SUB_WORK set IMPLEMENTED_INITIATIVES = #{implementedInitiatives,jdbcType=VARCHAR}, ",
            "DETAILED_DESCRIPTION = #{detailedDescription, jdbcType=VARCHAR}, PLAN_TIME = #{planTime, jdbcType=VARCHAR}, ",
            "COMPLETION_MARK = #{completionMark, jdbcType=VARCHAR}, CREATE_TIME = #{createTime, jdbcType=TIMESTAMP}, ",
            "DEL = #{del, jdbcType=INTEGER}, MAIN_WORK_ID = #{mainWorkId, jdbcType=VARCHAR}, ",
            "SUB_WORK_DESCRIPTION = #{subWorkDescription, jdbcType=VARCHAR}, REMARKS = #{remarks, jdbcType=VARCHAR}, ",
            "UPDATE_TIME = #{updateTime, jdbcType=TIMESTAMP} ",
            "where SUB_WORK_ID = #{subWorkId,jdbcType=VARCHAR}"
    })
    void updateCitySubWork(final TaskReminderSubWork subWork);

    /**
     * 修改市公司子表关联的主表信息
     * @param oldMainWorkId 旧主工单id
     * @param newMainWorkId 新主工单id
     */
    @Update({
            "update AITK_CITY_SUB_WORK set MAIN_WORK_ID = #{newMainWorkId, jdbcType=VARCHAR} ",
            "where MAIN_WORK_ID = #{oldMainWorkId,jdbcType=VARCHAR}"
    })
    void updateCitySubWorkByMainWorkId(@Param("oldMainWorkId") final String oldMainWorkId, @Param("newMainWorkId") final String newMainWorkId);

    /**
     * 删除市公司子表信息
     * @param subWorkIds 子表id
     */
    @Delete({
            "<script>",
            "delete from AITK_CITY_SUB_WORK where SUB_WORK_ID in ",
            "<foreach collection='subWorkIds' index='index' item='item' open='(' separator=',' close=')'>",
            "#{item}</foreach> ",
            "</script>"
    })
    void deleteCitySubWork(@Param("subWorkIds") final List<String> subWorkIds);

    /**
     * 根据主工单id查询主工单信息
     * @param mainWorkId 主工单编号
     * @return 主工单信息
     */
    @Select({
            "<script>",
            "SELECT ID, WORK_ORDER_ID, MATTER_DESCRIPTION, USER_ID, ",
            "SAN_KE_KEYWORDS, WORK_TYPE, CREATE_TIME, UPDATE_TIME, DEL, WORK_STATUS, SENDER_IDS, ",
            "USER_NAME, TASK_STATUS, ISSUED_TIME, FINISH_TIME ,PARENT_WORK_ID",
            "FROM AITK_CITY_MAIN_WORK",
            "where WORK_ORDER_ID = #{mainWorkId,jdbcType=VARCHAR}",
            "ORDER BY DECODE(WORK_STATUS, '未分派', WORK_STATUS), UPDATE_TIME DESC",
            "</script>"
    })
    @ResultMap(value = {"CityMainWorkMap"})
    TaskReminderMainWork getCityMainWorkByMainWorkId(@Param("mainWorkId") final String mainWorkId);

    /**
     * 市公司提醒列表查询信息
     * @param vo 查询条件
     * @return 市公司主表列表
     */
    @Select({
            "<script>",
            "SELECT A.ID, A.WORK_ORDER_ID, A.MATTER_DESCRIPTION, A.USER_ID, ",
            "A.SAN_KE_KEYWORDS, A.WORK_TYPE, A.CREATE_TIME, A.UPDATE_TIME, A.DEL, A.WORK_STATUS, A.SENDER_IDS, ",
            "A.COMPANY_NAME, A.HANDLER_ID, A.USER_NAME, A.HANDLER_NAME, A.READ_TYPE, A.PARENT_WORK_ID, A.TASK_STATUS, A.ISSUED_TIME, A.FINISH_TIME ",
            "FROM AITK_CITY_MAIN_WORK A ",
            "left join AITK_CITY_SUB_WORK B on A.WORK_ORDER_ID = B.MAIN_WORK_ID  where 1=1 ",
            "<if test=\"workStatus != null and workStatus != ''\"> AND A.WORK_STATUS=#{workStatus,jdbcType=VARCHAR} </if> ",
            "<if test=\"readType != null and readType != ''\"> AND A.READ_TYPE=#{readType,jdbcType=VARCHAR} </if> ",
            "<if test=\"companyName != null and companyName != ''\"> AND A.COMPANY_NAME=#{companyName,jdbcType=VARCHAR} </if> ",
            "<if test=\"startTime != null \"> AND A.UPDATE_TIME &gt;= #{startTime}</if> ",
            "<if test=\"endTime != null \"> AND A.UPDATE_TIME &lt;= #{endTime} </if> ",
            "GROUP BY A.ID, A.WORK_ORDER_ID, A.MATTER_DESCRIPTION, A.USER_ID, ",
            "A.SAN_KE_KEYWORDS, A.WORK_TYPE, A.CREATE_TIME, A.UPDATE_TIME, A.DEL, A.WORK_STATUS, A.SENDER_IDS, ",
            "A.COMPANY_NAME, A.HANDLER_ID, A.USER_NAME, A.HANDLER_NAME, A.READ_TYPE, A.PARENT_WORK_ID, A.TASK_STATUS, A.ISSUED_TIME, A.FINISH_TIME ",
            "ORDER BY DECODE(A.WORK_STATUS, '未分派', A.WORK_STATUS), A.UPDATE_TIME DESC",
            "</script>"
    })
    @Results(id = "CityMainWorkMap", value = {
            @Result(column = "ID", property = "id", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "WORK_ORDER_ID", property = "workOrderId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "MATTER_DESCRIPTION", property = "matterDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "USER_ID", property = "userId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "SAN_KE_KEYWORDS", property = "sanKeKeywords", jdbcType = JdbcType.VARCHAR),
            @Result(column = "WORK_TYPE", property = "workType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "CREATE_TIME", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "UPDATE_TIME", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "DEL", property = "del", jdbcType = JdbcType.INTEGER),
            @Result(column = "WORK_STATUS", property = "workStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "SENDER_IDS", property = "senderIds", jdbcType = JdbcType.VARCHAR),
            @Result(column = "COMPANY_NAME", property = "companyName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "HANDLER_ID", property = "handlerId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "USER_NAME", property = "userName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "HANDLER_NAME", property = "handlerName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "READ_TYPE", property = "readType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PARENT_WORK_ID", property = "parentWorkId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "TASK_STATUS", property = "taskStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ISSUED_TIME", property = "issuedTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "FINISH_TIME", property = "finishTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "SUB_WORK_DESCRIPTIONS", property = "subWorkDescriptions", jdbcType = JdbcType.VARCHAR),
            @Result(column = "DETAILED_DESCRIPTIONS", property = "detailedDescriptions", jdbcType = JdbcType.VARCHAR),
    })
    List<TaskReminderMainWork> getCityMainWorkList(final WorkReminderVo vo);

    /**
     * 查询市公司主工单信息
     * @param mainWork 查询条件
     * @return 主工单信息
     */
    @Select({
            "SELECT ID, WORK_ORDER_ID, MATTER_DESCRIPTION, USER_ID, ",
            "SAN_KE_KEYWORDS, WORK_TYPE, CREATE_TIME, UPDATE_TIME, DEL, WORK_STATUS, SENDER_IDS, ",
            "COMPANY_NAME, HANDLER_ID, USER_NAME, HANDLER_NAME, PARENT_WORK_ID, TASK_STATUS, ISSUED_TIME, FINISH_TIME",
            "FROM AITK_CITY_MAIN_WORK where COMPANY_NAME=#{companyName,jdbcType=VARCHAR} ",
            "and PARENT_WORK_ID=#{parentWorkId,jdbcType=VARCHAR} and ID != #{id,jdbcType=VARCHAR} ",
    })
    @ResultMap(value = {"CityMainWorkMap"})
    TaskReminderMainWork getCityMainWorkByIdAndParentWorkId(final TaskReminderMainWork mainWork);

    /**
     * 根据父工单id查询市公司主工单信息
     * @param mainWork 查询条件
     * @return 主工单信息
     */
    @Select({
            "SELECT ID, WORK_ORDER_ID, MATTER_DESCRIPTION, USER_ID, ",
            "SAN_KE_KEYWORDS, WORK_TYPE, CREATE_TIME, UPDATE_TIME, DEL, WORK_STATUS, SENDER_IDS, ",
            "COMPANY_NAME, HANDLER_ID, USER_NAME, HANDLER_NAME, PARENT_WORK_ID, TASK_STATUS, ISSUED_TIME ,FINISH_TIME ",
            "FROM AITK_CITY_MAIN_WORK where READ_TYPE='todo' ",
            "and PARENT_WORK_ID=#{workOrderId,jdbcType=VARCHAR} and ID != #{id,jdbcType=VARCHAR} ",
    })
    @ResultMap(value = {"CityMainWorkMap"})
    List<TaskReminderMainWork> getCityMainWorkByParentWorkId(final TaskReminderMainWork mainWork);

    /**
     * 根据id删除市公司主工单
     * @param ids ids
     */
    @Delete({
            "<script>",
            "delete from AITK_CITY_MAIN_WORK where ID in ",
            "<foreach collection='ids' index='index' item='item' open='(' separator=',' close=')'>",
            "#{item}</foreach> ",
            "</script>"
    })
    void deleteCityMainWorkById(@Param("ids") final List<String> ids);

    /**
     * 根据主工单id删除市公司子工单
     * @param mainWorkIds 主工单id
     */
    @Delete({
            "<script>",
            "delete from AITK_CITY_SUB_WORK where MAIN_WORK_ID in ",
            "<foreach collection='mainWorkIds' index='index' item='item' open='(' separator=',' close=')'>",
            "#{item}</foreach> ",
            "</script>"
    })
    void deleteCitySubWorkById(@Param("mainWorkIds") final List<String> mainWorkIds);

    /**
     * 根据主工单编号查询市公司子表列表查询信息
     * @param mainWork 查询条件
     * @return 市公司子表列表
     */
    @Select({
            "<script>",
            "SELECT ID, SUB_WORK_ID, IMPLEMENTED_INITIATIVES, DETAILED_DESCRIPTION, PLAN_TIME, ",
            "COMPLETION_MARK, CREATE_TIME, DEL, MAIN_WORK_ID, SUB_WORK_DESCRIPTION, REMARKS, UPDATE_TIME ",
            "FROM AITK_CITY_SUB_WORK ",
            "where MAIN_WORK_ID = #{workOrderId,jdbcType=VARCHAR}",
            "ORDER BY CREATE_TIME ASC",
            "</script>"
    })
    @ResultMap(value = {"SubWorkMap"})
    List<TaskReminderSubWork> getCitySubWorkList(final TaskReminderMainWork mainWork);

    /**
     * 查询支部主工单提醒列表
     * @param vo 查询条件
     * @return 支部主工单列表
     */
    @Select({
            "<script>",
            "SELECT A.ID, A.WORK_ORDER_ID, A.MATTER_DESCRIPTION, A.USER_ID, ",
            "A.SAN_KE_KEYWORDS, A.WORK_TYPE, A.CREATE_TIME, A.UPDATE_TIME, A.DEL, A.WORK_STATUS, ",
            "A.COMPANY_NAME, A.HANDLER_ID, C.ORG_SHORT_NAME, A.USER_NAME, A.HANDLER_NAME, A.PARENT_WORK_ID, A.FINISH_STATUS, A.MEETING_IDS, ",
            "A.ISSUED_TIME, A.FINISH_TIME, A.ORG_UUID ",
            "FROM AITK_BRANCH_MAIN_WORK A ",
            "left join AITK_BRANCH_SUB_WORK B on A.WORK_ORDER_ID = B.MAIN_WORK_ID ",
            "left join AITK_PARTY_ORG C on A.ORG_UUID = C.ORG_UUID ",
            "where 1=1 ",
            "<if test=\"workStatus != null and workStatus != ''\"> AND A.WORK_STATUS=#{workStatus,jdbcType=VARCHAR} </if> ",
            "<if test=\"readType != null and readType != ''\"> AND A.READ_TYPE=#{readType,jdbcType=VARCHAR} </if> ",
            "<if test=\"companyName != null and companyName != ''\"> AND A.COMPANY_NAME=#{companyName,jdbcType=VARCHAR} </if> ",
            "<if test=\"orgUuid != null and orgUuid != ''\"> AND A.ORG_UUID=#{orgUuid,jdbcType=VARCHAR} </if> ",
            "<if test=\"startTime != null \"> AND A.UPDATE_TIME &gt;= #{startTime}</if> ",
            "<if test=\"endTime != null \"> AND A.UPDATE_TIME &lt;= #{endTime} </if> ",
            "GROUP BY A.ID, A.WORK_ORDER_ID, A.MATTER_DESCRIPTION, A.USER_ID, ",
            "A.SAN_KE_KEYWORDS, A.WORK_TYPE, A.CREATE_TIME, A.UPDATE_TIME, A.DEL, A.WORK_STATUS, ",
            "A.COMPANY_NAME, A.HANDLER_ID, C.ORG_SHORT_NAME, A.USER_NAME, A.HANDLER_NAME, A.PARENT_WORK_ID, A.FINISH_STATUS, A.MEETING_IDS, ",
            "A.ISSUED_TIME, A.FINISH_TIME, A.ORG_UUID ",
            "ORDER BY A.FINISH_TIME asc",
            "</script>"
    })
    @Results(id = "BranchMainWorkMap", value = {
            @Result(column = "ID", property = "id", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "WORK_ORDER_ID", property = "workOrderId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "MATTER_DESCRIPTION", property = "matterDescription", jdbcType = JdbcType.VARCHAR),
            @Result(column = "USER_ID", property = "userId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "SAN_KE_KEYWORDS", property = "sanKeKeywords", jdbcType = JdbcType.VARCHAR),
            @Result(column = "WORK_TYPE", property = "workType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "CREATE_TIME", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "UPDATE_TIME", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "DEL", property = "del", jdbcType = JdbcType.INTEGER),
            @Result(column = "WORK_STATUS", property = "workStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "COMPANY_NAME", property = "companyName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "HANDLER_ID", property = "handlerId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ORG_SHORT_NAME", property = "partyBranch", jdbcType = JdbcType.VARCHAR),
            @Result(column = "USER_NAME", property = "userName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "HANDLER_NAME", property = "handlerName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PARENT_WORK_ID", property = "parentWorkId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "FINISH_STATUS", property = "finishStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "MEETING_IDS", property = "meetingIds", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ISSUED_TIME", property = "issuedTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "FINISH_TIME", property = "finishTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "SUB_WORK_DESCRIPTIONS", property = "subWorkDescriptions", jdbcType = JdbcType.VARCHAR),
            @Result(column = "DETAILED_DESCRIPTIONS", property = "detailedDescriptions", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ORG_UUID", property = "orgUuid", jdbcType = JdbcType.VARCHAR)
    })
    List<TaskReminderMainWork> getBranchMainWorkList(final WorkReminderVo vo);

    /**
     * 支部子表列表查询信息
     * @param mainWork 查询条件
     * @return 支部子表列表
     */
    @Select({
            "<script>",
            "SELECT ID, SUB_WORK_ID, IMPLEMENTED_INITIATIVES, DETAILED_DESCRIPTION, PLAN_TIME, ",
            "COMPLETION_MARK, CREATE_TIME, DEL, MAIN_WORK_ID, SUB_WORK_DESCRIPTION, REMARKS, UPDATE_TIME ",
            "FROM AITK_BRANCH_SUB_WORK ",
            "where MAIN_WORK_ID = #{workOrderId,jdbcType=VARCHAR}",
            "ORDER BY CREATE_TIME ASC",
            "</script>"
    })
    @ResultMap(value = {"SubWorkMap"})
    List<TaskReminderSubWork> getBranchSubWorkList(final TaskReminderMainWork mainWork);

    /**
     * 新增支部主表信息
     * @param mainWork 新增内容
     */
    @Insert({
            "insert into AITK_BRANCH_MAIN_WORK (ID, WORK_ORDER_ID, MATTER_DESCRIPTION, USER_ID, ",
            "SAN_KE_KEYWORDS, WORK_TYPE, CREATE_TIME, UPDATE_TIME, DEL, WORK_STATUS, ",
            "COMPANY_NAME, HANDLER_ID, PARTY_BRANCH, USER_NAME, HANDLER_NAME, PARENT_WORK_ID, FINISH_STATUS, MEETING_IDS, ",
            "ISSUED_TIME, FINISH_TIME, ORG_UUID) ",
            "values ",
            "(#{id,jdbcType=VARCHAR}, #{workOrderId,jdbcType=VARCHAR}, #{matterDescription,jdbcType=VARCHAR}, ",
            "#{userId,jdbcType=VARCHAR}, #{sanKeKeywords,jdbcType=VARCHAR}, ",
            "#{workType,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ",
            "#{del,jdbcType=INTEGER}, #{workStatus,jdbcType=VARCHAR}, ",
            "#{companyName,jdbcType=VARCHAR}, #{handlerId,jdbcType=VARCHAR}, ",
            "#{partyBranch,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, #{handlerName,jdbcType=VARCHAR}, ",
            "#{parentWorkId,jdbcType=VARCHAR}, #{finishStatus,jdbcType=VARCHAR}, #{meetingIds,jdbcType=VARCHAR}, ",
            "#{issuedTime,jdbcType=TIMESTAMP}, #{finishTime,jdbcType=TIMESTAMP}, #{orgUuid,jdbcType=VARCHAR} ) ",
    })
    void insertBranchMainWork(final TaskReminderMainWork mainWork);

    /**
     * 新增支部子表信息
     * @param subWorks 新增内容列表
     */
    @Insert({
            "insert into AITK_BRANCH_SUB_WORK(ID, SUB_WORK_ID, IMPLEMENTED_INITIATIVES, ",
            "DETAILED_DESCRIPTION, PLAN_TIME, COMPLETION_MARK, CREATE_TIME, DEL, MAIN_WORK_ID, SUB_WORK_DESCRIPTION, ",
            "REMARKS, UPDATE_TIME )",
            "values ",
            "(#{id, jdbcType=VARCHAR}, #{subWorkId, jdbcType=VARCHAR}, #{implementedInitiatives, jdbcType=VARCHAR}, ",
            "#{detailedDescription, jdbcType=VARCHAR}, #{planTime, jdbcType=VARCHAR}, #{completionMark, jdbcType=VARCHAR}, ",
            "#{createTime, jdbcType=TIMESTAMP}, #{del, jdbcType=INTEGER}, #{mainWorkId, jdbcType=VARCHAR}, ",
            "#{subWorkDescription, jdbcType=VARCHAR}, #{remarks, jdbcType=VARCHAR}, #{updateTime, jdbcType=TIMESTAMP} )",
    })
    void insertBranchSubWork(final TaskReminderSubWork subWorks);

    /**
     * 查询支部主工单信息
     * @param mainWork 查询条件
     * @return 主工单信息
     */
    @Select({
            "SELECT ID, WORK_ORDER_ID, MATTER_DESCRIPTION, USER_ID, ",
            "SAN_KE_KEYWORDS, WORK_TYPE, CREATE_TIME, UPDATE_TIME, DEL, WORK_STATUS, ",
            "COMPANY_NAME, HANDLER_ID, USER_NAME, HANDLER_NAME, PARENT_WORK_ID, FINISH_STATUS, MEETING_IDS, FINISH_TIME",
            "FROM AITK_BRANCH_MAIN_WORK where COMPANY_NAME=#{companyName,jdbcType=VARCHAR} ",
            "and PARENT_WORK_ID=#{workOrderId,jdbcType=VARCHAR} and ID != #{id,jdbcType=VARCHAR} ",
    })
    @ResultMap(value = {"BranchMainWorkMap"})
    List<TaskReminderMainWork> getBranchMainWorkByIdAndParentWorkId(final TaskReminderMainWork mainWork);

    /**
     * 查询支部主工单信息数量
     * @param workOrderId 查询条件
     * @return 主工单信息数量
     */
    @Select({
            "SELECT COUNT(0) ",
            "FROM AITK_BRANCH_MAIN_WORK where COMPANY_NAME=#{companyName,jdbcType=VARCHAR} ",
            "and PARENT_WORK_ID=#{workOrderId,jdbcType=VARCHAR} "
    })
    Integer getBranchMainWorkCountByParentWorkId(@Param("companyName") final String companyName, @Param("workOrderId") final String workOrderId);

    /**
     * 查询支部已完成的主工单数量
     * @param workOrderId 查询条件
     * @return 支部已完成的主工单数量
     */
    @Select({
            "SELECT COUNT(0) ",
            "FROM AITK_BRANCH_MAIN_WORK where COMPANY_NAME=#{companyName,jdbcType=VARCHAR} ",
            "and PARENT_WORK_ID=#{workOrderId,jdbcType=VARCHAR} AND FINISH_STATUS = '已完成' ",
    })
    Integer getBranchCountByParentWorkIdAndFinishStatus(@Param("companyName") final String companyName, @Param("workOrderId") final String workOrderId);

    /**
     * 查询支部主工单信息
     * @param mainWork 查询条件
     * @return 主工单信息
     */
    @Select({
            "SELECT A.ID, A.WORK_ORDER_ID, A.MATTER_DESCRIPTION, A.USER_ID, ",
            "A.SAN_KE_KEYWORDS, A.WORK_TYPE, A.CREATE_TIME, A.UPDATE_TIME, A.DEL, A.WORK_STATUS, ",
            "A.COMPANY_NAME, A.HANDLER_ID, A.USER_NAME, A.HANDLER_NAME, A.PARENT_WORK_ID, A.FINISH_STATUS, A.MEETING_IDS, ",
            "B.ORG_SHORT_NAME, A.FINISH_TIME, A.ORG_UUID ",
            "FROM AITK_BRANCH_MAIN_WORK A ",
            "LEFT JOIN AITK_PARTY_ORG B ON B.ORG_UUID = A.ORG_UUID ",
            "where A.COMPANY_NAME=#{companyName,jdbcType=VARCHAR} ",
            "and A.PARENT_WORK_ID=#{workOrderId,jdbcType=VARCHAR} "
    })
    @ResultMap(value = {"BranchMainWorkMap"})
    List<TaskReminderMainWork> getBranchMainWorkByParentWorkId(final TaskReminderMainWork mainWork);

    /**
     * 修改支部主表信息
     * @param mainWork 主表信息
     */
    @Update({
            "update AITK_BRANCH_MAIN_WORK set MATTER_DESCRIPTION = #{matterDescription,jdbcType=VARCHAR}, ",
            "USER_ID = #{userId,jdbcType=VARCHAR}, USER_NAME = #{userName,jdbcType=VARCHAR},",
            "SAN_KE_KEYWORDS = #{sanKeKeywords,jdbcType=VARCHAR}, WORK_TYPE = #{workType,jdbcType=VARCHAR}, ",
            "CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}, UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP}, ",
            "FINISH_TIME = #{finishTime,jdbcType=TIMESTAMP}, MEETING_IDS = #{meetingIds,jdbcType=TIMESTAMP}, ",
            "FINISH_STATUS = #{finishStatus,jdbcType=TIMESTAMP} ",
            "where WORK_ORDER_ID = #{workOrderId,jdbcType=VARCHAR}"
    })
    void updateBranchMainWork(final TaskReminderMainWork mainWork);

    /**
     * 根据id删除市公司主工单
     * @param ids ids
     */
    @Delete({
            "<script>",
            "delete from AITK_BRANCH_MAIN_WORK where ID in ",
            "<foreach collection='ids' index='index' item='item' open='(' separator=',' close=')'>",
            "#{item}</foreach> ",
            "</script>"
    })
    void deleteBranchMainWorkById(@Param("ids") final List<String> ids);

    /**
     * 根据主工单id删除支部公司子工单
     * @param mainWorkIds 主工单id
     */
    @Delete({
            "<script>",
            "delete from AITK_BRANCH_SUB_WORK where MAIN_WORK_ID in ",
            "<foreach collection='mainWorkIds' index='index' item='item' open='(' separator=',' close=')'>",
            "#{item}</foreach> ",
            "</script>"
    })
    void deleteBranchSubWorkById(@Param("mainWorkIds") final List<String> mainWorkIds);

    /**
     * 根据公司名删除人员信息
     * @param companyName
     */
    @Delete({
            "<script>",
            "delete from AITK_ISSUED_MEMBER ",
            "where <choose>",
            "<when test=\"companyName != null and companyName != ''\">COMPANY_NAME = #{companyName,jdbcType=VARCHAR} </when>",
            "<otherwise>COMPANY_NAME is null </otherwise>",
            "</choose>",
            "</script>"
    })
    void deleteDefaultMembers(@Param("companyName") final String companyName);

    /**
     * 新增下发人员名单
     * @param issuedMember 人员信息
     */
    @Insert({
            "insert into AITK_ISSUED_MEMBER (ID, ISSUED_TYPE, USER_ID, USER_NAME, DEL, COMPANY_NAME, ORG_SHORT_NAME, USER_TYPE)",
            "VALUES (#{id, jdbcType=VARCHAR}, #{issuedType, jdbcType=VARCHAR}, #{userId, jdbcType=VARCHAR}, ",
            "#{userName, jdbcType=VARCHAR}, #{del, jdbcType=INTEGER}, #{companyName, jdbcType=VARCHAR}, ",
            "#{orgShortName, jdbcType=VARCHAR}, #{userType, jdbcType=VARCHAR})"
    })
    void saveDefaultMembers(final IssuedMember issuedMember);

    /**
     * 查询人员信息
     * @param companyName 公司名称
     * @return 所属公司人员列表
     */
    @Select({
            "<script>",
            "select ID, ISSUED_TYPE, USER_ID, USER_NAME, DEL, COMPANY_NAME, ORG_SHORT_NAME, USER_TYPE from AITK_ISSUED_MEMBER ",
            "where <choose>",
            "<when test=\"companyName != null and companyName != ''\">COMPANY_NAME = #{companyName,jdbcType=VARCHAR} </when>",
            "<otherwise>COMPANY_NAME is null </otherwise>",
            "</choose>",
            "</script>"
    })
    @Results({
            @Result(column = "ID", property = "id", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "ISSUED_TYPE", property = "issuedType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "USER_ID", property = "userId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "USER_NAME", property = "userName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "DEL", property = "del", jdbcType = JdbcType.INTEGER),
            @Result(column = "COMPANY_NAME", property = "companyName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ORG_SHORT_NAME", property = "orgShortName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "USER_TYPE", property = "userType", jdbcType = JdbcType.VARCHAR),
    })
    List<IssuedMember> getIssuedMemberByCompanyName(@Param("companyName") final String companyName);

    /**
     * 插入文件信息
     * @param branchAttachment 文件信息
     */
    @Insert({
            "insert into AITK_BRANCH_ATTACHMENT (ID, MAIN_WORK_ID, ATTACHMENT, UPLOADER_TIME, FILE_NAME, UPLOADER_UID, UPLOADER_NAME)",
            "values (#{id,jdbcType=VARCHAR}, #{mainWorkId,jdbcType=VARCHAR}, #{attachment,jdbcType=BINARY}, #{uploaderTime,jdbcType=TIMESTAMP}, #{fileName,jdbcType=VARCHAR}, ",
            "#{uploaderUid,jdbcType=VARCHAR}, #{uploaderName,jdbcType=VARCHAR} )"
    })
    void insertBranchAttachment(final BranchAttachment branchAttachment);

    /**
     * 根据主工单id获取附件信息
     * @param mainWorkId 主工单id
     * @return 附件信息
     */
    @Select({
            "select ID, MAIN_WORK_ID, UPLOADER_TIME, FILE_NAME, UPLOADER_UID, UPLOADER_NAME ",
            "from AITK_BRANCH_ATTACHMENT where MAIN_WORK_ID = #{mainWorkId,jdbcType=VARCHAR} "
    })
    @Results(id = "BranchAttachmentMap", value = {
            @Result(column = "ID", property = "id", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "MAIN_WORK_ID", property = "mainWorkId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "UPLOADER_TIME", property = "uploaderTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "FILE_NAME", property = "fileName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "UPLOADER_UID", property = "uploaderUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "UPLOADER_NAME", property = "uploaderName", jdbcType = JdbcType.VARCHAR),
    })
    List<BranchAttachment> getBranchAttachmentByMainWorkId(@Param("mainWorkId") final String mainWorkId);

    /**
     * 根据id获取附件信息
     * @param id id
     * @return 附件信息
     */
    @Select({
            "select ID, MAIN_WORK_ID, ATTACHMENT, UPLOADER_TIME, FILE_NAME, UPLOADER_UID, UPLOADER_NAME ",
            "from AITK_BRANCH_ATTACHMENT where ID = #{id,jdbcType=VARCHAR} "
    })
    @ResultMap(value = {"BranchAttachmentMap"})
    BranchAttachment getBranchAttachmentById(@Param("id") final String id);

    /**
     * 根据id删除附件
     * @param id id
     */
    @Delete({
            "delete from AITK_BRANCH_ATTACHMENT  where ID = #{id,jdbcType=VARCHAR} "
    })
    void deleteBranchAttachmentById(@Param("id") final String id);

}
